package com.ruoyi.live.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.live.domain.TbRoom;
import com.ruoyi.live.service.ITbRoomService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 直播房间Controller
 * 
 * @author sun
 * @date 2023-01-30
 */
@RestController
@RequestMapping("/room")
public class TbRoomController extends BaseController
{
    @Autowired
    private ITbRoomService tbRoomService;

    /**
     * 查询直播房间列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbRoom tbRoom)
    {
        startPage();
        List<TbRoom> list = tbRoomService.selectTbRoomList(tbRoom);
        return getDataTable(list);
    }

    /**
     * 导出直播房间列表
     */
    @Log(title = "直播房间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbRoom tbRoom)
    {
        List<TbRoom> list = tbRoomService.selectTbRoomList(tbRoom);
        ExcelUtil<TbRoom> util = new ExcelUtil<TbRoom>(TbRoom.class);
        util.exportExcel(response, list, "直播房间数据");
    }

    /**
     * 获取直播房间详细信息
     */
    @GetMapping(value = "getRoomById/{roomId}")
    public AjaxResult getInfo(@PathVariable("roomId") Integer roomId)
    {
        return success(tbRoomService.selectTbRoomByRoomId(roomId));
    }

    /**
     * 新增直播房间
     */
//    @RequiresPermissions("live:room:add")
    @Log(title = "直播房间", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TbRoom tbRoom)
    {
        return toAjax(tbRoomService.insertTbRoom(tbRoom));
    }

    /**
     * 修改直播房间
     */
//    @RequiresPermissions("live:room:edit")
    @Log(title = "直播房间", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody TbRoom tbRoom)
    {
        return toAjax(tbRoomService.updateTbRoom(tbRoom));
    }

    /**
     * 删除直播房间
     */
    @Log(title = "直播房间", businessType = BusinessType.DELETE)
	@DeleteMapping("delById/{roomIds}")
    public AjaxResult remove(@PathVariable Integer[] roomIds)
    {
        return toAjax(tbRoomService.deleteTbRoomByRoomIds(roomIds));
    }
}
